package com.example.demo.controller;


import com.example.demo.entity.user;
import com.example.demo.mapper.UserMapper;
import jakarta.servlet.http.HttpServletResponse;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
public class loginController {

    @Autowired
    private UserMapper usermapper;
    @PostMapping("/login")
    public String login(String uNum,String uPw) {
        System.out.println("输入的参数为u:"+uNum);//参数传递（json）
        List<user> list = usermapper.findByuNm(uNum);
        if(list == null||list.isEmpty()){
            return "用户名或密码错误";
        }
            else{
                         if(Objects.equals(list.get(0).getuPw(), uPw)){
                             if(list.get(0).getuRole() == 1){
                                 return "zHome.html";
                             }
                             else return "jHome.html";
                         }
                         else{
                        return "用户名或密码错误";
                           }
            }
    }
}
